fetch("../data/sample.csv")
  .then(res => res.text())
  .then(csv => {
    const rows = csv.trim().split("\n").slice(1).map(line => line.split(","));
    const ids = rows.map(r => r[0]);
    const score1 = rows.map(r => +r[5]);
    const score2 = rows.map(r => +r[6]);
    const score3 = rows.map(r => +r[7]);
    const categories = rows.map(r => r[4]);

    // 折线图
    Plotly.newPlot("lineChart", [{ x: ids, y: score1, type: "scatter", mode: "lines+markers" }], { title: "Score1 折线图" });

    // 饼图
    const counts = {};
    categories.forEach(c => counts[c] = (counts[c] || 0) + 1);
    Plotly.newPlot("pieChart", [{
      labels: Object.keys(counts),
      values: Object.values(counts),
      type: "pie"
    }], { title: "Category 饼图" });

    // 3D 散点图
    Plotly.newPlot("scatter3D", [{
      x: score1, y: score2, z: score3,
      mode: "markers",
      type: "scatter3d",
      marker: { size: 5 }
    }], { title: "三维能力分布图" });
  });
